<template>
    <view class="container">
        <image class="bg-image" src="/static/image.jpg" mode="aspectFill"></image>
        
        <view class="nav-bar">
            <view class="back-btn" @click="goBack">
                <image src="/static/return.png" mode="aspectFit"class="back-icon" />
            </view>
            <text class="nav-title">学习记录</text>
        </view>

        <view class="records-list">
            <view class="record-item" v-for="(record, index) in recordsList" :key="index">
                <view class="word-section">
                    <text class="word-name">{{ record.word_name }}</text>
                    <view class="pronounce-section">
                        <text class="soundmark">{{ record.word_soundmark }}</text>
                        <view class="sound-btn" @click="playPronunciation(record.word_pronounce)">
                            <image src="/static/me.png" mode="aspectFit" class="sound-icon"/>
                        </view>
                    </view>
                </view>
                <view class="meaning-section">
                    <text class="meaning-text">{{ record.word_paraphrase }}</text>
                </view>
                <view class="record-info">
                    <text class="learning-times">学习次数：{{ record.learning_times }}</text>
                    <text class="update-time">最后学习：{{ formatTime(record.update_time) }}</text>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import { records } from '@/api/user.js'

export default {
    data() {
        return {
            recordsList: [],
            audioContext: null
        }
    },
    onLoad() {
        this.audioContext = uni.createInnerAudioContext()
        this.loadRecords()
    },
    methods: {
        goBack() {
            uni.navigateBack()
        },
        async loadRecords() {
            try {
                const res = await records()
                console.log('获取记录响应：', res)
                if (res.code === '2000') {
                    this.recordsList = res.data[0]
                    console.log('处理后的记录列表：', this.recordsList)
                } else {
                    uni.showToast({
                        title: res.message || '获取记录失败',
                        icon: 'none'
                    })
                }
            } catch (error) {
                console.error('获取记录失败：', error)
                uni.showToast({
                    title: '获取记录失败，请重试',
                    icon: 'none'
                })
            }
        },
        playPronunciation(url) {
            if (url) {
                this.audioContext.src = url
                this.audioContext.play()
            }
        },
        formatTime(timeStr) {
            if (!timeStr) return '';
            const date = new Date(timeStr);
            return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
        }
    }
}
</script>

<style>
.container {
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

.bg-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    padding: 40px 20px 20px;
    z-index: 100;
}

.back-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-icon {
    width: 35px;
    height: 35px;
}

.nav-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 500;
    color: #333;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}


.records-list {
    margin-top: 80px;
    padding: 0 20px;
    position: relative;
    z-index: 2;
    height: calc(100vh - 80px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.records-list::-webkit-scrollbar {
    width: 4px;
}

.records-list::-webkit-scrollbar-track {
    background: transparent;
}

.records-list::-webkit-scrollbar-thumb {
    background: rgba(107, 75, 138, 0.3);
    border-radius: 2px;
}

.record-item {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 15px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s ease;
}

.record-item:active {
    transform: scale(0.98);
}

.word-section {
    margin-bottom: 15px;
}

.word-name {
    font-size: 20px;
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
    display: block;
}

.pronounce-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.soundmark {
    font-size: 14px;
    color: #666;
}

.sound-btn {
    padding: 5px;
}

.sound-icon {
    width: 20px;
    height: 20px;
}

.meaning-text {
    font-size: 16px;
    color: #333;
    line-height: 1.5;
}

.record-info {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #666;
}

.learning-times {
    color: #6b4b8a;
}

.update-time {
    color: #666;
}
</style> 